<?php 
class Sunnet_Encrypt_Aes{
	function aes128Encrypt($key, $data) {
		$block = mcrypt_get_block_size('rijndael_128', 'ecb');
		$pad = $block - (strlen($data) % $block);
		$data .= str_repeat(chr($pad), $pad);
		return (mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_ECB));
	}
	function aes128Decrypt($key, $data) {
		//$data = base64_decode($str);
		$data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_ECB);
		$block = mcrypt_get_block_size('rijndael_128', 'ecb');
		$pad = ord($data[($len = strlen($data)) - 1]);
		$len = strlen($data);
		$pad = ord($data[$len-1]);
		return substr($data, 0, strlen($data) - $pad);
	}
}